package com.monkeybrother.thread.factory;


import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Desc 处理轨迹文件备份的线程池
 * @Author houruiyang
 * @Date 2021/11/12
 **/
public class SmartDeviceTrackFileThreadPoolSingleton {

    private static volatile ThreadPoolExecutor robotTrackFileThreadSingleton;

    private SmartDeviceTrackFileThreadPoolSingleton() {
    }

    public static ThreadPoolExecutor getInstance() {
        if (null == robotTrackFileThreadSingleton) {
            synchronized (SmartDeviceTrackFileThreadPoolSingleton.class) {
                if (null == robotTrackFileThreadSingleton) {
                    robotTrackFileThreadSingleton = new ThreadPoolExecutor(200,
                           200,
                            10L,
                            TimeUnit.SECONDS,
                            new LinkedBlockingQueue<>(30000),
                            new ThreadNameFactory("轨迹文件上传"),
                            new ThreadPoolExecutor.DiscardPolicy());
                }
            }
        }
        return robotTrackFileThreadSingleton;
    }

    public static void shutDown() {
        robotTrackFileThreadSingleton.shutdown();
    }

}
